//package com.ysj.aipicturebe.config.MqConfig;
//
//import lombok.RequiredArgsConstructor;
//import org.springframework.amqp.core.Binding;
//import org.springframework.amqp.core.BindingBuilder;
//import org.springframework.amqp.core.DirectExchange;
//import org.springframework.amqp.core.Queue;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.rabbit.retry.MessageRecoverer;
//import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//@RequiredArgsConstructor
//public class ErrorMessageConfig {
//    // 注入RabbitTemplate，用于消息操作
//    private final RabbitTemplate rabbitTemplate;
//
//    // 定义Direct类型的交换机，名称为error.direct
//    @Bean
//    public DirectExchange errorMessageExchange(){
//        return new DirectExchange("error.direct");
//    }
//
//    // 定义持久化队列，名称为error.queue
//    @Bean
//    public Queue errorQueue(){
//        return new Queue("error.queue", true);
//    }
//
//    // 将error.queue队列绑定到error.direct交换机，路由键为error
//    @Bean
//    public Binding errorBinding(Queue errorQueue, DirectExchange errorMessageExchange){
//        return BindingBuilder.bind(errorQueue).to(errorMessageExchange).with("error");
//    }
//
//    // 定义消息重试失败后的处理器，将失败消息重新发布到error.direct交换机
//    @Bean
//    public MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){
//        return new RepublishMessageRecoverer(rabbitTemplate, "error.direct", "error");
//    }
//
//}